package runner

import (
	"io"
	"os"
)

type Out struct {
	w          io.Writer
	fd         uintptr
	isTerminal bool
}

func (o *Out) Write(b []byte) (n int, err error) {
	return o.w.Write(b)
}

func (o *Out) FD() uintptr {
	return o.fd
}

func (o *Out) IsTerminal() bool {
	return o.isTerminal
}

func NewOut(w io.Writer) *Out {
	out := &Out{
		w: w,
	}
	var inFd uintptr
	var isTerminalIn bool
	if file, ok := w.(*os.File); ok {
		inFd = file.Fd()
		isTerminalIn = false
	}

	out.isTerminal = isTerminalIn
	out.fd = inFd

	return out
}
